package com.wu.store.dao;

import com.wu.store.entity.Cart;
import com.wu.store.entity.OrderInst;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CartDao {
	@Select("<script>" +
		        "select * from v_cart_goods " +
		        "<where>" +
		        "<if test='uid != null'>" +
		        "uid = #{uid}" +
		        "</if>" +
		        "</where>" +
		        "</script>")
	List<Cart> list(Long uid);

	@Select("<script>" +
		        "select * from v_cart_goods " +
		        "<where>" +
		        "id in (<foreach collection='idList' item='id' separator=','>#{id}</foreach>)" +
		        "<if test='uid != null'>" +
		        " and uid = #{uid}" +
		        "</if>" +
		        "</where>" +
		        " order by create_time desc" +
		        "</script>")
	List<Cart>
	selectByUidAndIdIn(Long uid, @Param("idList") List<Long> idList);

	@Insert(value = "insert into t_cart (uid, goods_id, create_goods_price, goods_count, create_time) values (#{uid}, #{goodsId}, #{createGoodsPrice},#{goodsCount}, #{createTime})")
	int add(Cart cart);

	@Update("update t_cart set goods_count = #{goodsCount}, update_time = #{updateTime} where id = #{id} and uid = #{uid}")
	int update(Cart cart);

	@Delete("delete from t_cart where id = #{id} and uid = #{uid}")
	int delete(Cart cart);

	@Delete("<script>" +
		        "delete from t_cart " +
		        "<where>" +
		        " id in (" +
		        "<foreach collection='idList' item='id' separator=','>" +
		        " #{id}" +
		        "</foreach>" +
		        ")" +
		        "<if test='uid != null'>" +
		        " and uid = #{uid}" +
		        "</if>" +
		        "</where>" +
		        "</script>")
	int batchDelete(Long uid, List<Long> idList);

	@Select("<script>" +
		        "select * from v_cart_goods " +
		        "<where>" +
		        "id = #{id} " +
		        "<if test='uid != null'>" +
		        " and uid = #{uid}" +
		        "</if>" +
		        "</where>" +
		        "</script>")
	Cart selectById(Cart cart);


}
